<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<#include "../inc/commonJs.html"/>
<title>系统中心</title>
<script type="text/javascript">
var frozenColumns = [ [ {
	field : 'id',
	checkbox : true,
	rowspan : 2
}] ];

// 定义标题栏
var columns = [ [ {
	field : 'title',
	title : '标题',
	width : 200,
	align : 'left'
}, {
	field : 'editor',
	title : '作者',
	align : 'center'
},{
	field : 'name',
	title : '栏目',
	align : 'center'
}, {
	field : 'updatetime',
	title : '日期',
	align : 'center'
}, {
	field : 'picnews',
	title : '图片信息',
	align : 'center',
	formatter:function(value,row,index){
		if(value==1){
			return '是';
		}else{
			return '否';
		}
	}
}, {
	field : 'checked',
	title : '审核',
	align : 'center',
	formatter:function(value,row,index){
		if(value==1){
			return '<a href="javascript:docheck('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">已通过</span></span></a>';
		}else{
			return '<a href="javascript:docheck('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">待审核</span></span></a>';
		}
	}
}, {
	field : 'istop',
	title : '置顶',
	align : 'center',
	formatter:function(value,row,index){
		if(value==1){
			return '<a href="javascript:dotop('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text"><font color="red">是</font></span></span></a>';
		}else{
			return '<a href="javascript:dotop('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text">否</span></span></a>';
		}
	}
}, {
	field : 'daodu',
	title : '精华',
	align : 'center',
	formatter:function(value,row,index){
		if(value==1){
			return '<a href="javascript:dojh('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text"><font color="red">是</font></span></span></a>';
		}else{
			return '<a href="javascript:dojh('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text">否</span></span></a>';
		}
	}
}, {
	field : 'goodnews',
	title : '推荐',
	align : 'center',
	formatter:function(value,row,index){
		if(value==1){
			return '<a href="javascript:dogoodnews('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text"><font color="red">是</font></span></span></a>';
		}else{
			return '<a href="javascript:dogoodnews('+row.id+','+value+')" class="l-btn l-btn-plain" id=""><span class="l-btn-left"><span class="l-btn-text">否</span></span></a>';
		}
	}
} ]];

function selects(){
	var ids = [];
	var items = $('#checkgrid').datagrid('getSelections');
	if(items.length == 0){
		$.messager.alert("信息提示","请选择信息","error");
		return ;
	}
	for(var i=0; i<items.length; i++){
	    ids.push(items[i].id);	    
	}
	return ids;
}

function docheck(id,state){
	doupdate("myNewsChkact.do",id,state)
}
function dotop(id,state){
	doupdate("myNewsTOP.do",id,state);
}
function dojh(id,state){
	doupdate("myNewsDaodu.do",id,state);
}
function dogoodnews(id,state){
	doupdate("myNewsGood.do",id,state);
}
function doupdate(url,id,state){
	if(state==1){
		state=0;
	}else{
		state=1;
	}
	$.post(url, {id :id,state:state }, function(data){
		$.messager.show({
			title:'信息提示',
			msg:data
		});
		$("#checkgrid").datagrid('reload');
		$('#checkgrid').datagrid('uncheckAll'); // 取消所有元素选中效果
	});
}

$(function(){
	checkgrid();
	$('#lanmutree').tree({
		url:'alltypeTree.do',
	    lines:true,
	    animate:true,
	    onClick: function(node){
	    	var array = getNode(node);
	    	$('#checkgrid').datagrid('load',{typeid:array.join(",")});
		}
	}); 
});
	function checkgrid(){
		$('#checkgrid').datagrid( {
			iconCls : 'icon-forward',
			fitColumns:true,
			rownumbers : true,
			striped : true,
			singleSelect:true,
			loadMsg : '数据装载中......',
	         pageSize: [${syscfg.pageSize!10}],
	         pageList: [${syscfg.pageList!10}],
			pagination : true,
			toolbar : '#tb',
			url : "myNewsCheck.do",
			idField : 'id', 
			frozenColumns : frozenColumns,
			columns : columns,
			onClickRow : onClickRow,
			onDblClickRow : doDblClickRow
		});
		//
		$('#seachinput').searchbox({
			searcher:function(value,name){
				$('#checkgrid').datagrid({
					queryParams: {
						searchtype: name,
						keyword: value
					}
				});
				//$('#checkgrid').datagrid('reload');
			}, 
			menu:'#seachdiv', 
			prompt:'搜索信息' 
		}); 
	}		
	// 双击
	function doDblClickRow(rowIndex, rowData) {
		window.parent.open('查看信息','info/newsView.do?newsid='+rowData.id);
	}
	// 单击
	function onClickRow(rowIndex){
	}
	//
	function doView() {
		var item = $('#checkgrid').datagrid('getSelected');
		if(item!=null){
			if (window.top.$("#tabs").tabs('exists', '查看信息')) {
				window.top.$('#tabs').tabs('close', '查看信息');
			}
			window.parent.open('查看信息','info/newsView.do?newsid='+item.id);
		}else{
			$.messager.alert("信息提示","查看信息必须选中一行","error");
		}
	}
	
	function doEdit() {
		var item = $('#checkgrid').datagrid('getSelected');
		if(item!=null){
			if (window.top.$("#tabs").tabs('exists', '编辑信息')) {
				window.top.$('#tabs').tabs('close', '编辑信息');
			}
			window.parent.open('编辑信息','info/newsEdit.do?newsid='+item.id);
		}else{
			$.messager.alert("信息提示","编辑信息必须选中一行","error");
		}
	}

	function doDelete() {
		var ids = [];
		var items = $('#checkgrid').datagrid('getSelections');
		if(items.length == 0){
			$.messager.alert("信息提示","请选择要删除的信息","error");
			return ;
		}
		$.messager.confirm("操作提示", "删除信息！",function(r){
			if(r){
				for(var i=0; i<items.length; i++){
				    ids.push(items[i].id);	    
				}
				// 先删除 后 reload
				 $.post("delmyNews.do", {newsid :ids.join(",") }, function(data){
					 if(data=='"删除成功"'){
							$.messager.show({
								title:'信息提示',
								msg:data
							});
							$("#checkgrid").datagrid('reload');
							$('#checkgrid').datagrid('uncheckAll'); // 取消所有元素选中效果
						}else{
							$.messager.show({
								title:'信息提示',
								msg:data
							});
						}
				});  
			}
		});
	}
	function getNode(node){
		var array = [];
		if(node.id!=0){
			var nodes = $('#lanmutree').tree('getChildren',node.target);
			array.push(node.id);
			for(var i=0;i<nodes.length;i++){
				array.push(nodes[i].id);
			}
		}
		return array;
	}
	//
	function restore(){
		$('#searchtable input').val('');
		$('#searchtable select').val('');
		//$('#checkgrid').datagrid('reload',{});
	}
</script>	
</head>
<body>
<div align="center" class="easyui-panel" data-options='fit:true,border:false'>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'west',iconCls:'icon-mini-add',title:'按栏目查找',border:true,split:true" style="width: 180px;">
		<ul id="lanmutree" class="easyui-tree"></ul>  
	</div>
	<div data-options="region:'center',border:true">
		<div class="easyui-layout" id="centerTable" data-options="fit:true">
			<div data-options="region:'center'">
			   	<table id="checkgrid" data-options="fit:true,border:false"></table>
			</div>
		</div>
	</div>
	<div id="tb" style="display: none;">
	<table border="0" cellpadding="0" cellspacing="0">
	<tr><td>
		<a href="javascript:doView()" id="button-view" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">查看</a>
		<a href="javascript:doEdit()" id="button-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
		<a href="javascript:doDelete()" id="button-delete" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a>
	</td>
	<td valign="center"><div class="datagrid-btn-separator"></div></td>
	<td>
		<input id="seachinput"></input> 
		<div id="seachdiv" style="width:120px">
			<div data-options="name:'0',iconCls:'icon-mini-edit'">搜索标题</div>
			<div data-options="name:'1',iconCls:'icon-mini-add'">搜索作者</div>
		</div>
	</td></tr>
	</table>	
	</div>
</div>
</div>
</body>
</html>